package com.qf.demo.controller;


import com.github.pagehelper.PageInfo;
import com.qf.demo.model.TbPhohe;
import com.qf.demo.model.TbPhsort;
import com.qf.demo.service.DengluService;

import com.qf.demo.model.TbUser;

import com.qf.demo.service.IndexService;
import com.qf.demo.service.Sortservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/denglu")

public class DengluServlet {

    @Autowired
    private DengluService dengluService;
    @Autowired
    private IndexService indexService;
    @Autowired
    private Sortservice sortservice;
    @RequestMapping("/findall")
    public String findAll(TbUser tbUser,Model model,Integer id,boolean t,Integer start) {
        boolean is = dengluService.findUser(tbUser);
        if (id==0){
            t=false;
            id=1;
        }else {
            t=true;
        }
        if (is||t){
            List<TbPhohe> list=indexService.findphone();
            PageInfo<TbPhsort> pageInfo= sortservice.findsort(id ,start,2);
            model.addAttribute("list",list);
            model.addAttribute("pageInfo",pageInfo);
            System.out.println(pageInfo);
            return "index";
        }
        else {
            return  "register";
        }

    }

//    @RequestMapping("/findphone")
//    public String findphone(TbUser tbUser) {
//        boolean is = dengluService.findUser(tbUser);
//        System.out.prIntegerln(is);
//        if (is){
//            return "index";
//        }
//        else {
//            return  "login";
//        }
//
//    }
}
